<html>
<head><meta charset="utf-8"><title>tuple-structs · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/tuple-structs.html">tuple-structs</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="136071165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/tuple-structs/near/136071165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/tuple-structs.html#136071165">(Oct 18 2018 at 20:55)</a>:</h4>
<p>Is there any reason why tuple struct constructors aren't treated as <code>const fn</code>s or was this overlooked?</p>
<div class="codehilite"><pre><span></span><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">i32</span> <span class="p">{</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">B</span><span class="p">();</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="n">R</span>: <span class="kt">i32</span> <span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="o">*&amp;</span><span class="n">f</span><span class="p">)();</span><span class="w"> </span><span class="c1">// OK</span>
<span class="k">const</span><span class="w"> </span><span class="n">S</span>: <span class="nc">B</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="o">*&amp;</span><span class="n">B</span><span class="p">)();</span><span class="w"> </span><span class="c1">// ERROR</span>
</pre></div>



<a name="136092102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/tuple-structs/near/136092102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/tuple-structs.html#136092102">(Oct 19 2018 at 06:14)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> seems reasonable that we could make them <code>const fn</code>, I think. What about enum constructors?</p>



<a name="136094328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/tuple-structs/near/136094328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/tuple-structs.html#136094328">(Oct 19 2018 at 07:16)</a>:</h4>
<p>huh... that seems like a bug, that should definitely work, considering that <code>B()</code> works. I think the issue is that our function call code explicitly checks for calls to the tuple struct constructor instead of just checking the zst type. <code>const T: B = (B, B).1();</code> also does not work</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>